using System.Collections;
using System.Collections.Generic;
using System.Text.RegularExpressions;
using UnityEngine;
namespace UMPRelease
{
    public class VersionHandle : ScriptableObject
    {
        public TextAsset PackageJson;

        public TextAsset ChangeLog;

        public PackageData PackageConfig;

        public GitHandleData SyncGit;


        public static PackageData ParsePackageJson(string jsonString)
        {
            try
            {
                return JsonUtility.FromJson<PackageData>(jsonString);
            }
            catch (System.Exception e)
            {
                UnityEngine.Debug.LogError($"Package JSON 解析失败: {e.Message}");
                return null;
            }
        }

        public void Refresh()
        {
            if (PackageJson != null)
                PackageConfig = ParsePackageJson(PackageJson.text);
            else
            {
                UnityEngine.Debug.LogWarning("package.json lost.");
            }
        }

        // 或者更严格的版本
        public bool IsValidVersionStrict(string version)
        {
            string pattern = @"^(0|[1-9]\d*)\.(0|[1-9]\d*)\.(0|[1-9]\d*)$";
            return Regex.IsMatch(version, pattern);
        }
    }
}